<template>
	<div>
		<span>
			<font class="font" size="5" color="grey">患者化验费用查询</font>
		</span>
		<el-divider></el-divider>
		<el-form :inline="true" :model="formInline" class="demo-form-inline">
			<el-form-item label="就诊卡ID:" required="">
				<el-input v-model="formInline.idnumber" placeholder="请输入就诊卡ID"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="gettestmoney()">搜索</el-button>
			</el-form-item>
		</el-form>
		<el-table :data="testmoneydata" border show-summary :summary-method="getSummaries" show-summary
			style="width: 100%">
			<el-table-column prop="num" label="化验流水号" width="180">
			</el-table-column>
			<el-table-column prop="name" label="姓名">
			</el-table-column>
			<el-table-column prop="project" label="项目名称">
			</el-table-column>
			<el-table-column prop="room" label="执行科室">
			</el-table-column>
			<el-table-column prop="money" label="消费金额">
			</el-table-column>
		</el-table>
	</div>
</template>

<script>
	import {
		showMsgTitle
	} from '@/utils/api'
	import {
		showMsgConfirm
	} from '@/utils/api'
	import {
		getRequest
	} from '@/utils/api'
	import {
		postRequest
	} from '@/utils/api'
	import {
		uploadFileRequest
	} from '@/utils/api'
	import {
		putRequest
	} from '@/utils/api'
	import {
		deleteRequest
	} from '@/utils/api'
	import {
		showConstants
	} from '@/utils/api'
	import {
		mapMutations
	} from "vuex";
	export default {
		data() {
			return {
				formInline: {
					idnumber: '',
				},
				testmoneydata: []
			}
		},
		methods: {
			gettestmoney() {
				this.$axios.get('http://localhost:8081/idptest?idnumber=' + this.formInline.idnumber).then((result) => {
					console.log(result.data);
					this.testmoneydata = result.data
				}).catch((err) => {
					console.log(error);
				});
			},

		},
		getSummaries(param) {
			const {
				columns,
				data
			} = param;
			const sums = [];
			columns.forEach((column, index) => {
				if (index === 0) {
					sums[index] = '总价';
					return;
				}

				if (index === 1) {
					sums[index] = ' ';
					return;
				}

				if (index === 2) {
					sums[index] = ' ';
					return;
				}

				if (index === 3) {
					sums[index] = ' ';
					return;
				}
				const values = data.map(item => Number(item[column.property]));
				if (!values.every(value => isNaN(value))) {
					sums[index] = values.reduce((prev, curr) => {
						const value = Number(curr);
						if (!isNaN(value)) {
							return prev + curr;
						} else {
							return prev;
						}
					}, 0);
					sums[index] += ' 元';
				} else {
					sums[index] = 'N/A';
				}
			});

			return sums;
		}
	}
</script>

<style>
	.font {
		margin-bottom: 20px;
	}
</style>
